package oakclub.background;

import oakclub.entity.BackgroundEntity;
import oakclub.global.Context;
import org.apache.commons.lang3.SerializationUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class BaseBackground
{
    private final Logger logger = LoggerFactory.getLogger(BaseBackground.class);

    protected interface IExecute
    {
        public void execute(BackgroundEntity entity) throws Exception;

    }

    protected void execute(byte[] bytes, IExecute f)
    {
        try
        {
            BackgroundEntity entity = (BackgroundEntity) SerializationUtils.deserialize(bytes);

            // set context
            Context.set(entity.getContext());

            // execute
            f.execute(entity);
        }
        catch(Exception e)
        {
            this.logger.warn("background issue", e);
        }
    }
}
